
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys


GITEE_URL='http://gismsl.gitee.io/html/'


f_index_html=r'index.html'
f_index=open(f_index_html,'w',encoding="UTF-8")
f_index.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
f_index.write("\n<html xmlns=\"http://www.w3.org/1999/xhtml\">")
f_index.write("\n<head>")
f_index.write("\n	<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>")
f_index.write("\n	<title>博客</title>")
f_index.write("\n	<link rel=\"stylesheet\" href=\"./css/jquery.treeview.css\" />")
f_index.write("\n	<link rel=\"stylesheet\" href=\"./css/screen.css\" />")
f_index.write("\n	<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js\"></script>")
f_index.write("\n	<script src=\"./js/jquery.cookie.js\"></script>")
f_index.write("\n    <script src=\"./js/jquery.treeview.js\"></script>")
f_index.write("\n	<script type=\"text/javascript\" src=\"./js/demo.js\"></script>")
f_index.write("\n	</head>")
f_index.write("\n	<body>")
f_index.write("\n<h1 id=\"banner\"><a href=\"http://bassistance.de/jquery-plugins/jquery-plugin-treeview/\">jQuery Treeview Plugin</a> Demo</h1>")
f_index.write("\n	<div id=\"main\">")
f_index.write("\n<h4>Sample 4 - two trees with one tree control, black and gray theme, cookie-based persistance</h4>")
f_index.write("\n		<div id=\"treecontrol\">")
f_index.write("\n			<a title=\"Collapse the entire tree below\" href=\"#\"><img src=\"./images/minus.gif\" /> Collapse All</a>")
f_index.write("\n			<a title=\"Expand the entire tree below\" href=\"#\"><img src=\"./images/plus.gif\" /> Expand All</a>")
f_index.write("\n			<a title=\"Toggle the tree below, opening closed branches, closing open branches\" href=\"#\">Toggle All</a>")
f_index.write("\n		</div>")
f_index.write("\n	")
f_index.write("\n		<ul id=\"gray\" class=\"treeview-gray filetree\">")


def write_folder(f_index,file,dirs,url,index):
    # f_index.write("\n<ul>")
    f_index.write("\n<li>")
    f_index.write("\n<span class=\"folder closed\">"+file+"</span>")
    f_index.write("\n<ul>")
    generator_html(os.path.join(dirs,file),url+"/"+file,(index+1)%2)
    f_index.write("\n</ul>")
    f_index.write("\n</li>")
    # f_index.write("\n</ul>")

def generator_html(dirs,url,index):
    files=os.listdir(dirs)
    for file in files:
        if file in ('assets','images','js','css') or file.startswith("."):
            continue
            
        if os.path.isdir(os.path.join(dirs,file)):
            write_folder(f_index,file,dirs,url,index)
        else:
            f_index.write("\n<li><a href="+url+"/"+file+">"+file+"</a></li>")

directorys=r'E:\msl\git\html'
fils=os.listdir(directorys)
for file in fils:
    if file in ('assets','images','js','css') or file.startswith("."):
        continue
    if os.path.isdir(os.path.join(directorys,file)):
        # generator_html(os.path.join(directorys,file),GITEE_URL,0)
        write_folder(f_index,file,directorys,GITEE_URL,0)
f_index.write("\n</ul>")
f_index.write("\n</body>")
f_index.write("\n</html>")


